using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using Lib;
using NHibernate.Mapping.Attributes;
using System.ComponentModel;

namespace Persistance.Model
{

    /* Problem Object Specification.
     * 
     * ProblemID (int) --> The unique identifier for the problem
     * Name (varchar 200) --> The Name of the project. This is how the user will distinguish Problems
     * SituationID (int) --> The unique Situation Object that his Problem is associated with.
     * 
     * *************
     * What fields for "What Object"
     * *************
     * WhatObjectIs (text) 
     * WhatObjectIsNot (text) 
     * WhatObjectDistinction (text)
     * WhatObjectChange (text) 
     * 
     * *************
     * What Fields for "What Deviation"
     * *************
     * WhatDeviationIs (text)
     * WhatDeviationIsNot (text)
     * WhatDeviationDistinction (text)
     * WhatDeviationChange (text)
     * 
     * *************
     * Where fields for "Where Geographically"
     * *************
     * WhereGeoIs
     * WhereGeoIsNot
     * WhereGeoDistinction
     * WhereGeoChange
     * 
     * ************
     * Where fields for "Where on the Object"
     * ************
     * WhereObjectIs
     * WhereObjectIsNot
     * WhereObjectDistinction
     * WhereObjectChange
     * 
     * ************
     * When fields for "When First"
     * ************
     * WhenFirstIs
     * WhenFirstIsNot
     * WhenFirstDistinction
     * WhenFirstChange
     * 
     * ************
     * When fields for "When Since"
     * ************
     * WhenSinceIs
     * WhenSinceIsNot
     * WhenSinceDistinction
     * WhenSinceChange
     * 
     * ************
     * When fields for "When in the Life Cycle"
     * ************
     * WhenCycleIs
     * WhenCycleIsNot
     * WhenCycleDistinction
     * WhenCycleChange
     * 
     * ***********
     * Extent fields for "How Many Objects"
     * ***********
     * ExtentNumberIs
     * ExtentNumberIsNot
     * ExtentNumberDistinction
     * ExtentNumberChange
     * 
     * ***********
     * Extent fields for "What is the Size"
     * ***********
     * ExtentSizeIs
     * ExtentSizeIsNot
     * ExtentSizeDistinction
     * ExtentSizeChange
     * 
     * ***********
     * Extent fields for "What is the Trend"
     * ***********
     * ExtentTrendIs
     * ExtentTrendIsNot
     * ExtentTrendDistinction
     * ExtentTrendChange
     * 
     * AuthorID (string) --> Identifies the original Author of the PA
     * LastEditedBy (string) --> Identifies the Author that last made changes to the PA
     * CreatedOn (datetime) --> The Date the PA was created
     * LastEditedOn (datetime) --> The Date of the last edit to the PA
     * */

    [Serializable]
    [Class]
    public class Problem
    {

        private int _problemID;
        //NHIBER: Setts the primary key to ID
        [Id(Name = "ProblemID")]
        [Generator(1, Class = "native")]
        public virtual int ProblemID
        {
            get { return _problemID; }
            set { _problemID = value; }
        }

        private string _problemStatement;
        [Property(Length = 500)]
        public virtual string ProblemStatement
        {
            get { return _problemStatement; }
            set { _problemStatement = value; }
        }

        //Retrieves all problem causes associated with this Problem
        private IList<ProblemCauses> _problemCauses = new List<ProblemCauses>();
        [Bag(1, Cascade = CascadeStyle.AllDeleteOrphan)]
        [Key(2, Column = "ProblemID", ForeignKey = "FK_ProblemID")]
        [OneToMany(3, ClassType = typeof(ProblemCauses))]
         public virtual IList<ProblemCauses> ProblemCauses
        {
            get { return _problemCauses; }
            set { _problemCauses = value; }
        }

        //Retrives the Situation that this Problem is associated with. Returns a list to match up with NHibernate .List() method
        private Situation _situation = new Situation();
        public virtual Situation Situation
        {
            get { return _situation; }
            set { _situation = value; }
        }


        #region " WhatObject Fields " 

        private string _whatObjectIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatObjectIs
        {
            get { return _whatObjectIs; }
            set { _whatObjectIs = value; }
        }

        private string _whatObjectIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatObjectIsNot
        {
            get { return _whatObjectIsNot; }
            set { _whatObjectIsNot = value; }
        }

        private string _whatObjectDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatObjectDistinction
        {
            get { return _whatObjectDistinction; }
            set { _whatObjectDistinction = value; }
        }

        private string _whatObjectChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatObjectChange
        {
            get { return _whatObjectChange; }
            set { _whatObjectChange = value; }
        }

        private string _whatObjectIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatObjectIsDC
        {
            get { return _whatObjectIsDC; }
            set { _whatObjectIsDC = value; }
        }

        private string _whatObjectIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatObjectIsNotDC
        {
            get { return _whatObjectIsNotDC; }
            set { _whatObjectIsNotDC = value; }
        }


        #endregion

        #region "WhatDeviation Fields"

        private string _whatDeviationIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatDeviationIs
        {
            get { return _whatDeviationIs; }
            set { _whatDeviationIs = value; }
        }

        private string _whatDeviationIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatDeviationIsNot
        {
            get { return _whatDeviationIsNot; }
            set { _whatDeviationIsNot = value; }
        }

        private string _whatDeviationDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatDeviationDistinction
        {
            get { return _whatDeviationDistinction; }
            set { _whatDeviationDistinction = value; }
        }

        private string _whatDeviationChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatDeviationChange
        {
            get { return _whatDeviationChange; }
            set { _whatDeviationChange = value; }
        }

        private string _whatDeviationIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatDeviationIsDC
        {
            get { return _whatDeviationIsDC; }
            set { _whatDeviationIsDC = value; }
        }

        private string _whatDeviationIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhatDeviationIsNotDC
        {
            get { return _whatDeviationIsNotDC; }
            set { _whatDeviationIsNotDC = value; }
        }
        #endregion

        #region "WhereGeo Fields"

        private string _whereGeoIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereGeoIs
        {
            get { return _whereGeoIs; }
            set { _whereGeoIs = value; }
        }

        private string _whereGeoIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereGeoIsNot
        {
            get { return _whereGeoIsNot; }
            set { _whereGeoIsNot = value; }
        }

        private string _whereGeoDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereGeoDistinction
        {
            get { return _whereGeoDistinction; }
            set { _whereGeoDistinction = value; }
        }

        private string _whereGeoChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereGeoChange
        {
            get { return _whereGeoChange; }
            set { _whereGeoChange = value; }
        }

        private string _whereGeoIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereGeoIsDC
        {
            get { return _whereGeoIsDC; }
            set { _whereGeoIsDC = value; }
        }

        private string _whereGeoIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereGeoIsNotDC
        {
            get { return _whereGeoIsNotDC; }
            set { _whereGeoIsNotDC = value; }
        }

        #endregion

        #region "WhereObject Fields"

        private string _whereObjectIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereObjectIs
        {
            get { return _whereObjectIs; }
            set { _whereObjectIs = value; }
        }

        private string _whereObjectIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereObjectIsNot
        {
            get { return _whereObjectIsNot; }
            set { _whereObjectIsNot = value; }
        }

        private string _whereObjectDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereObjectDistinction
        {
            get { return _whereObjectDistinction; }
            set { _whereObjectDistinction = value; }
        }

        private string _whereObjectChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereObjectChange
        {
            get { return _whereObjectChange; }
            set { _whereObjectChange = value; }
        }

        private string _whereObjectIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereObjectIsDC
        {
            get { return _whereObjectIsDC; }
            set { _whereObjectIsDC = value; }
        }

        private string _whereObjectIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhereObjectIsNotDC
        {
            get { return _whereObjectIsNotDC; }
            set { _whereObjectIsNotDC = value; }
        }

        #endregion

        #region "WhenFirst Fields"

        private string _whenFirstIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenFirstIs
        {
            get { return _whenFirstIs; }
            set { _whenFirstIs = value; }
        }

        private string _whenFirstIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenFirstIsNot
        {
            get { return _whenFirstIsNot; }
            set { _whenFirstIsNot = value; }
        }

        private string _whenFirstDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenFirstDistinction
        {
            get { return _whenFirstDistinction; }
            set { _whenFirstDistinction = value; }
        }

        private string _whenFirstChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenFirstChange
        {
            get { return _whenFirstChange; }
            set { _whenFirstChange = value; }
        }

        private string _whenFirstIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenFirstIsDC
        {
            get { return _whenFirstIsDC; }
            set { _whenFirstIsDC = value; }
        }

        private string _whenFirstIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenFirstIsNotDC
        {
            get { return _whenFirstIsNotDC; }
            set { _whenFirstIsNotDC = value; }
        }

        #endregion

        #region "WhenSince Fields"

        private string _whenSinceIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenSinceIs
        {
            get { return _whenSinceIs; }
            set { _whenSinceIs = value; }
        }

        private string _whenSinceIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenSinceIsNot
        {
            get { return _whenSinceIsNot; }
            set { _whenSinceIsNot = value; }
        }

        private string _whenSinceDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenSinceDistinction
        {
            get { return _whenSinceDistinction; }
            set { _whenSinceDistinction = value; }
        }

        private string _whenSinceChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenSinceChange
        {
            get { return _whenSinceChange; }
            set { _whenSinceChange = value; }
        }

        private string _whenSinceIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenSinceIsDC
        {
            get { return _whenSinceIsDC; }
            set { _whenSinceIsDC = value; }
        }

        private string _whenSinceIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenSinceIsNotDC
        {
            get { return _whenSinceIsNotDC; }
            set { _whenSinceIsNotDC = value; }
        }

        #endregion

        #region "WhenCycle Fields"

        private string _whenCycleIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenCycleIs
        {
            get { return _whenCycleIs; }
            set { _whenCycleIs = value; }
        }

        private string _whenCycleIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenCycleIsNot
        {
            get { return _whenCycleIsNot; }
            set { _whenCycleIsNot = value; }
        }

        private string _whenCycleDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenCycleDistinction
        {
            get { return _whenCycleDistinction; }
            set { _whenCycleDistinction = value; }
        }

        private string _whenCycleChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenCycleChange
        {
            get { return _whenCycleChange; }
            set { _whenCycleChange = value; }
        }

        private string _whenCycleIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenCycleIsDC
        {
            get { return _whenCycleIsDC; }
            set { _whenCycleIsDC = value; }
        }

        private string _whenCycleIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string WhenCycleIsNotDC
        {
            get { return _whenCycleIsNotDC; }
            set { _whenCycleIsNotDC = value; }
        }

        #endregion

        #region "ExtentNumber Fields"

        private string _extentNumberIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentNumberIs
        {
            get { return _extentNumberIs; }
            set { _extentNumberIs = value; }
        }

        private string _extentNumberIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentNumberIsNot
        {
            get { return _extentNumberIsNot; }
            set { _extentNumberIsNot = value; }
        }

        private string _extentNumberDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentNumberDistinction
        {
            get { return _extentNumberDistinction; }
            set { _extentNumberDistinction = value; }
        }

        private string _extentNumberChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentNumberChange
        {
            get { return _extentNumberChange; }
            set { _extentNumberChange = value; }
        }

        private string _extentNumberIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentNumberIsDC
        {
            get { return _extentNumberIsDC; }
            set { _extentNumberIsDC = value; }
        }

        private string _extentNumberIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentNumberIsNotDC
        {
            get { return _extentNumberIsNotDC; }
            set { _extentNumberIsNotDC = value; }
        }

        #endregion

        #region "ExtentSize Fields"

        private string _extentSizeIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentSizeIs
        {
            get { return _extentSizeIs; }
            set { _extentSizeIs = value; }
        }

        private string _extentSizeIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentSizeIsNot
        {
            get { return _extentSizeIsNot; }
            set { _extentSizeIsNot = value; }
        }

        private string _extentSizeDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentSizeDistinction
        {
            get { return _extentSizeDistinction; }
            set { _extentSizeDistinction = value; }
        }

        private string _extentSizeChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentSizeChange
        {
            get { return _extentSizeChange; }
            set { _extentSizeChange = value; }
        }

        private string _extentSizeIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentSizeIsDC
        {
            get { return _extentSizeIsDC; }
            set { _extentSizeIsDC = value; }
        }

        private string _extentSizeIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentSizeIsNotDC
        {
            get { return _extentSizeIsNotDC; }
            set { _extentSizeIsNotDC = value; }
        }

        #endregion

        #region "ExtentTrends Fields"

        private string _extentTrendsIs;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentTrendsIs
        {
            get { return _extentTrendsIs; }
            set { _extentTrendsIs = value; }
        }

        private string _extentTrendsIsNot;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentTrendsIsNot
        {
            get { return _extentTrendsIsNot; }
            set { _extentTrendsIsNot = value; }
        }

        private string _extentTrendsDistinction;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentTrendsDistinction
        {
            get { return _extentTrendsDistinction; }
            set { _extentTrendsDistinction = value; }
        }

        private string _extentTrendsChange;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentTrendsChange
        {
            get { return _extentTrendsChange; }
            set { _extentTrendsChange = value; }
        }

        private string _extentTrendsIsDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentTrendsIsDC
        {
            get { return _extentTrendsIsDC; }
            set { _extentTrendsIsDC = value; }
        }

        private string _extentTrendsIsNotDC;
        [Property(Type = "StringClob", Length = 5000)]
        public virtual string ExtentTrendsIsNotDC
        {
            get { return _extentTrendsIsNotDC; }
            set { _extentTrendsIsNotDC = value; }
        }

        #endregion


        /// <summary>
        /// Retrieves or sets the Author that originally started the PA
        /// </summary>
        private Users _author = null;
        [ManyToOne(Column = "AuthorID", ForeignKey = "FK_ProblemAuthor")]
        public virtual Users Author
        {
            get { return _author; }
            set { _author = value; }
        }
        
        /// <summary>
        /// Retrieves or sets the User that last updated the PA. Returns null if no such User exists
        /// </summary>
        private Users _lastUpdatedBy = null;
        [ManyToOne(Column = "LastUpdatedBy", ForeignKey = "FK_ProblemLastUpdatedByAuthor")]
        public virtual Users LastUpdatedBy
        {
            get { return _lastUpdatedBy; }
            set { _lastUpdatedBy = value; }
        }

        /// <summary>
        /// Gets or Sets the Date that the PA was originally created on
        /// </summary>
        private DateTime _createdOn = new DateTime(1008, 1, 1);
        [Property(Type = ("DateTime"))]
        public virtual DateTime CreatedOn
        {
            get { return _createdOn; }
            set { _createdOn = value; }
        }

        private DateTime _edittedOn = new DateTime(2008, 1, 1);
        [Property(Type = ("DateTime"))]
        public virtual DateTime EdittedOn
        {
            get { return _edittedOn; }
            set { _edittedOn = value; }
        }



        public virtual void Create()
        {
            ISession sess = Persistor.CurrentSession;
            try
            {
                sess.Transaction.Begin();
                sess.Save(this);
                sess.Transaction.Commit();
                sess.Flush();
            }
            catch (Exception e)
            {
                sess.Transaction.Rollback();
                throw new Exception("akljsghp", e);
            }
        }
    }
}
